package com.lsfb.signln.Location.TaskMsg.Replenish;

import android.content.Intent;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.lsfb.signln.Login.LoginActivity;
import com.lsfb.signln.R;
import com.lsfb.signln.Utils.LittleUtils;
import com.lsfb.signln.Utils.URLString;
import com.zgscwjm.lsfbbasetemplate.Event.EventAnnotation;
import com.zgscwjm.lsfbbasetemplate.LsfbActivity;
import com.zgscwjm.lsfbbasetemplate.annotation.ContentView;
import com.zgscwjm.lsfbbasetemplate.annotation.OnClick;
import com.zgscwjm.lsfbbasetemplate.annotation.ViewInject;
import com.zgscwjm.lsfbbasetemplate.internet.BaseInternet;
import com.zgscwjm.lsfbbasetemplate.utils.T;

import java.util.HashMap;

/**
 * 补录
 * Created by Administrator on 2018/1/25 0025.
 */
@ContentView(R.layout.aty_replenish)
public class ReplenishActivity extends LsfbActivity {

    /**
     * 头像
     */
    @ViewInject(R.id.img_head)
    private SimpleDraweeView img_head;
    @ViewInject(R.id.aty_replenish_head)
    private RelativeLayout rl_replenish_head;
    @ViewInject(R.id.aty_replenish_text_head)
    private TextView tv_head;

    /**
     * 姓名
     */
    @ViewInject(R.id.aty_replenish_text_name)
    private TextView text_name;

    /**
     * 职位
     */
    @ViewInject(R.id.aty_replenish_text_position)
    private TextView text_position;

    /**
     * 补录时间
     */
    @ViewInject(R.id.aty_replenish_text_time)
    private TextView text_time;

    /**
     * 补录原因
     */
    @ViewInject(R.id.aty_replenish_text_cause)
    private TextView text_cause;

    /**
     * 出差地址
     */
    @ViewInject(R.id.aty_replenish_text_address)
    private TextView text_address;

    private String rid;

    @Override
    public void initView() {
        LittleUtils.setsimpletitlebar(this, "补录详情");
        if (getIntent().getStringExtra("rid") != null) {
            rid = getIntent().getStringExtra("rid");
        } else {
            T.showShort(this, "获取数据异常");
            this.finish();
        }

        getData();
    }

    /**
     * 得到请求补录的记录
     */
    private void getData() {
        HashMap hashMap = new HashMap();
        hashMap.put("rid", rid);
        new BaseInternet().getData_Get(URLString.SHOWRESIGN, hashMap, ReplenishBean.class, new ReplenishEvent<ReplenishBean>(), true, false);

    }

    @EventAnnotation
    public void eventResult(ReplenishEvent<ReplenishBean> event) {
        switch (event.getCode()) {
            case 200:
                if (event.getData().getHeadimg() != null && !event.getData().getHeadimg().isEmpty()) {
                    img_head.setVisibility(View.VISIBLE);
                    rl_replenish_head.setVisibility(View.GONE);
                    img_head.setImageURI(URLString.IMAGES + event.getData().getHeadimg());
                } else {
                    img_head.setVisibility(View.GONE);
                    rl_replenish_head.setVisibility(View.VISIBLE);
                    tv_head.setText(event.getData().getTureName().substring(event.getData().getTureName().length() - 2, event.getData().getTureName().length()));
                }
                text_name.setText(event.getData().getTureName());
                text_position.setText(event.getData().getDepartName());
                text_time.setText(event.getData().getTime().substring(0, 10));
                text_cause.setText(event.getData().getReason());
                text_address.setText(event.getData().getAddress());
                break;
            case 1006:
                T.showShort(this, "您的账号已在其它设备登录，请重登录");
                LittleUtils.exit(this);
                startActivity(new Intent(this, LoginActivity.class));
                break;
            default:
                T.showShort(this, event.getMsg());
                break;
        }
    }

    @Override
    public void initEvent() {

    }

    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.aty_leave_text_refuse, R.id.aty_leave_text_pass})
    public void onClick(View view) {
        switch (view.getId()) {
            //拒绝
            case R.id.aty_leave_text_refuse:
                auditResign("0");
                break;
            //同意
            case R.id.aty_leave_text_pass:
//                startActivity(new Intent(this, SignatureActivity.class).putExtra("type", "2"));
                auditResign("1");
                break;
        }
    }

    /**
     * 审批补录请求
     *
     * @param results 结果 拒绝0 同意1
     */
    private void auditResign(String results) {
        HashMap hashMap = new HashMap();
        hashMap.put("tid", rid);
        hashMap.put("results", results);
        if (text_cause.getText().toString().length() != 0) {
            hashMap.put("content", text_cause.getText().toString());
        }
        new BaseInternet().getData_Get(URLString.AUDITRESIGN, hashMap, String.class, new AuditResignEvent<String>(), true, false);
    }

    @EventAnnotation
    public void eventResult(AuditResignEvent<String> event) {
        switch (event.getCode()) {
            case 200:
                this.finish();
                break;
            case 1006:
                T.showShort(this, "您的账号已在其它设备登录，请重登录");
                LittleUtils.exit(this);
                startActivity(new Intent(this, LoginActivity.class));
                break;
            default:
                T.showShort(this, event.getMsg());
                break;
        }
    }

    @Override
    public void initData() {

    }
}
